const Router = require('koa-router')
const bookDao = require('../dao/bookDao')
const router = new Router();

router.get('/book/getAll' , async (ctx) => {
  ctx.body = await bookDao.getAllBook();
})

router.get('/book/getBookById/:id' , async (ctx) => {
  const { id } = ctx.params;
  ctx.body = await bookDao.getBookById(id);
})

router.get('/book/getBookByKetWord/:keyword' , async (ctx) => {
  const { keyword } = ctx.params;
  ctx.body = await bookDao.getBookByKetWord(keyword);
})

router.get('/book/getType/:type' , async (ctx) => {
  const { type } = ctx.params;
  ctx.body = await bookDao.query(`SELECT * FROM book WHERE type='${type}'`)
})

module.exports = router;